define([], function() {
	return {
		title: ['<a href="user.html">个人中心</a>', "系统管理", "商户认证管理"],
		init: function(content) {
			let form = content.children("form");
			let table = content.children("table");
			let search = form.serializeArray();
			let roleId = content.find("select[name='roleId']");
			let shopStatusTemplate = content.find("._shopStatusTemplate");
			let tableInit = function() {
				let actionEvent = {
					"click .temp1": function(e, value, row) {
						toastr.info("查看详情[" + row.userRealName + "]开发中...");
					},
					"change .shopStatus": function(e, value, row) {
						e.target.disabled = true;
						$.post(
							"shops/pass.do", {
								"id": row.id,
								"shopStatus": e.target.value
							},
							function(data) {
								e.target.disabled = false;
								if(data.ok) {
									toastr.success("修改审核状态成功");
								} else {
									toastr.error("修改审核状态失败：" + data.message);
								}
							}, "json"
						);
					},
					
					"click .temp": function(e, value, row) {}
				};
				let st = ["外卖","酒店"];
				table.bootstrapTable({
					url: 'shops/page.do', // 表格数据来源
					method: "get",
					sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
					pageNumber: 1, //初始化加载第一页，默认第一页
					pageSize: 10, //每页的记录行数（*）
					pageList: [5, 10, 15, 20, 30, 50], //可供选择的每页的行数（*）
					pagination: true, //是否显示分页（*）
					dataField: "content",
					toolbar: form,
					queryParamsType: "",
					queryParams: function(p) {
						let ps = [].concat(search);
						ps.push({
							"name": "current",
							"value": p.pageNumber
						});
						ps.push({
							"name": "rowMax",
							"value": p.pageSize
						});
						ps.push({
							"name": "sortName",
							"value": p.sortName
						});
						ps.push({
							"name": "sortOrder",
							"value": p.sortOrder
						});
						return ps;
					},
					columns: [{
							field: 'userName',
							title: '用户名',
							width: 100
						}, {
							field: 'shopName',
							title: '商铺名称',
							width: 100
						}, {
							field: 'shopTypeId',
							title: '类型',
							align: "center",
							width: 100,
							formatter: function(value, row, index, field) {
								return st[value];
							}
						}, {
							field: 'shopCreateTime',
							title: '创建时间',
							align: "center",
							width: 120
						}, {
							field: 'shopStatus',
							align: "center",
							title: '审核状态',
							width: 120,
							events: actionEvent,
							formatter: function(value, row, index, field) {
								let s = shopStatusTemplate.children("select");
								s.children().removeAttr("selected").filter("[value='" + value + "']").attr("selected", "selected");
								return shopStatusTemplate.html();
							}
						}, {
							field: 'temp1',
							align: "center",
							title: '查看详情',
							width: 100,
							events: actionEvent,
							formatter: function(value, row, index, field) {
								return '<a data-shops="'+row.id+'" href="javascript:void(0);">查看详情</a>';
							}
						}

					]
					
				});
			};
			form.on("submit", function() {
				search = form.serializeArray();
				table.bootstrapTable('refresh');
				return false;
			});
					
			let navLis = content.children("ul.nav:eq(0)").children("li");
			
			console.info(navLis);
			
			navLis.each(function(i,ele){
				let item  = $(ele);
				item.click(function(){
					if(!item.is(".active")){
						navLis.removeClass("active");
						item.addClass("active");
						form.trigger("reset");
						form.find("[name='shopStatus']").val(i);
						form.trigger("submit");
					}
				});
			});
			
			tableInit();
		}
	}
});